package club.kingyin.kyblog.core.business.mapper;

import club.kingyin.kyblog.core.business.dao.Comment;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

/**
 * @author : kingyins
 * @version : 1.0
 * @program : ky-blog
 * @description : 在此处添加类描述
 * @create : 2021年08月27日 17:19
 **/
@Mapper
public interface CommentMapper {

    @Insert("insert into comments value(null,#{fromUserAvatar},#{fromUserName},#{toUserId},#{createTime},#{content},#{docId},0)")
    int insert(Comment comment);

    @Delete("delete from comments where id = #{id}")
    int deleteById(int id);

    @Delete("delete from comments where docId = #{id}")
    int deleteByDocId(int id);

    @Select("select docId from comments where id = #{id}")
    int selectDocIdById(int id);

    @Select("select status from comments where id = #{id}")
    int selectStatusById(int id);

    @Update("update comments set status = 1 where id = #{id}")
    int updateStatusById(int id, int status);

    @Select("select id, fromUserAvatar, fromUserName, toUserId, createTime, content from comments where docId = #{id} and status = 1")
    ArrayList<Comment> selectByDocId(int id);

    @Select("select id,content,createTime,fromUserName,status,docId from comments where docId = #{id}")
    ArrayList<Comment> selectContentByDOcId(int id);

}
